package com.demo.datastructure.reorder.insertionSort;

import com.demo.datastructure.reorder.Example;

/**
 * @description: 插入排序
 * @author: ljr
 * @time: 2021/8/30 20:39
 */
public class SimpleInsertSort implements Example {

    @Override
    public void sort(Comparable[] a) {
        int length = a.length;
        for(int i = 1; i < length; i++){
            Comparable val = a[i];
            int l = i-1;
            for(; l >= 0; l--){
                if(less(val, a[l])){
                    a[l+1] = a[l];
                }else{
                    break;
                }
            }
            a[l+1] = val;
        }
    }
}
